<template>
  <a-cascader 
    :options="options" 
    placeholder="选择课程" 
    style="width:350px;"
    @change="onChange" />
</template>
<script>
import {getMajorListApi,getCommonCourseListApi} from "@/request/api"
export default {
    data() {
        return {
            options: [],
        };
    },
    created(){
        this.init()
    },
    methods: {
        init(){
            this.getToken(getMajorListApi,{},res=>{
                this.options=res.data.map(item=>({'label':item.name,'value':item.id,'children':item.children.map(value=>({'label':value.name,'value':value.id}))}))
                this.options.forEach(major=>{
                    major.children.forEach(modules=>{
                        this.getToken(getCommonCourseListApi,{'majorId':modules.value},res=>{
                            modules.children=res.data.map(course=>({'label':course.title,'value':course.id}))
                        })
                    })
                })
            })
        },
        onChange(data) {
            this.$emit('changeCourse',data)
        }
    },
};
</script>